<?php
function create_table_qa(){
	//CREATE qa TABLE
	$query="CREATE TABLE IF NOT EXISTS `qa` (
	  `Id` int(11) NOT NULL AUTO_INCREMENT,
	  `TITLE` varchar(101) DEFAULT NULL,
	  `CONTENT` text,
	  `AUTHOR` int(15) NOT NULL DEFAULT '0',
	  `DATETIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
	  `TYPE` int(2) NOT NULL DEFAULT '0',
	  PRIMARY KEY (`Id`)
	) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=9
	";
	mysql_query($query);
}
function create_table_qacomment(){
	$query="CREATE TABLE IF NOT EXISTS `qacomment` (
		  `Id` int(11) NOT NULL AUTO_INCREMENT,
		  `CONTENT` text,
		  `TITLEID` int(11) DEFAULT NULL,
		  `DATETIME` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
		  `AUTHOR` int(15) DEFAULT NULL,
		  PRIMARY KEY (`Id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4
	";
	mysql_query($query);
}
function alter_table_user_add_newsright(){
	$query="ALTER TABLE `user` ADD `NEWSRIGHT` INT( 2 ) NOT NULL DEFAULT '0' AFTER `LEVEL` ";
	mysql_query($query);
}
function alter_table_user_add_status(){
	$query="ALTER TABLE `user` ADD `STATUS` INT( 2 ) NOT NULL DEFAULT '0'";
	mysql_query($query);
}
function alter_table_user_add_lastsignin(){
	$query="ALTER TABLE `user` ADD `LASTLOGIN` DATETIME NULL DEFAULT NULL";
	mysql_query($query);
}
function alter_table_sysinfo_add(){
	$query="ALTER TABLE `sysinfo` ADD `BBSSWITCH` INT( 2 ) NOT NULL DEFAULT '1' AFTER `SEMESTERSTART` ";
	mysql_query($query);
}
function alter_table_qa_add(){
	$query="ALTER TABLE `qa` ADD `IPADDRESS` VARCHAR( 15 ) NOT NULL ";
	mysql_query($query);
}
function create_table_mrbs_area(){
	$query="
			CREATE TABLE IF NOT EXISTS `mrbs_area` (
			  `id` int(11) NOT NULL AUTO_INCREMENT,
			  `area_name` varchar(30) DEFAULT NULL,
			  `area_admin_email` text,
			  `resolution` int(11) DEFAULT NULL,
			  `default_duration` int(11) DEFAULT NULL,
			  `morningstarts` int(11) DEFAULT NULL,
			  `morningstarts_minutes` int(11) DEFAULT NULL,
			  `eveningends` int(11) DEFAULT NULL,
			  `eveningends_minutes` int(11) DEFAULT NULL,
			  `private_enabled` tinyint(1) DEFAULT NULL,
			  `private_default` tinyint(1) DEFAULT NULL,
			  `private_mandatory` tinyint(1) DEFAULT NULL,
			  `private_override` varchar(32) DEFAULT NULL,
			  `min_book_ahead_enabled` tinyint(1) DEFAULT NULL,
			  `min_book_ahead_secs` int(11) DEFAULT NULL,
			  `max_book_ahead_enabled` tinyint(1) DEFAULT NULL,
			  `max_book_ahead_secs` int(11) DEFAULT NULL,
			  `custom_html` text,
			  `provisional_enabled` tinyint(1) DEFAULT NULL,
			  `reminders_enabled` tinyint(1) DEFAULT NULL,
			  PRIMARY KEY (`id`)
			) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
	";
	mysql_query($query);
}
function create_table_mrbs_entry(){
	$query="
		CREATE TABLE IF NOT EXISTS `mrbs_entry` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `start_time` int(11) NOT NULL DEFAULT '0',
		  `end_time` int(11) NOT NULL DEFAULT '0',
		  `entry_type` int(11) NOT NULL DEFAULT '0',
		  `repeat_id` int(11) NOT NULL DEFAULT '0',
		  `room_id` int(11) NOT NULL DEFAULT '1',
		  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `create_by` varchar(80) NOT NULL DEFAULT '',
		  `name` varchar(80) NOT NULL DEFAULT '',
		  `type` char(1) NOT NULL DEFAULT 'E',
		  `description` text,
		  `private` tinyint(1) NOT NULL DEFAULT '0',
		  `status` tinyint(4) NOT NULL DEFAULT '1',
		  `reminded` int(11) DEFAULT NULL,
		  PRIMARY KEY (`id`),
		  KEY `idxStartTime` (`start_time`),
		  KEY `idxEndTime` (`end_time`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=6 ;
	";
	mysql_query($query);
}
function create_table_mrbs_repeat(){
	$query="
		CREATE TABLE IF NOT EXISTS `mrbs_repeat` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `start_time` int(11) NOT NULL DEFAULT '0',
		  `end_time` int(11) NOT NULL DEFAULT '0',
		  `rep_type` int(11) NOT NULL DEFAULT '0',
		  `end_date` int(11) NOT NULL DEFAULT '0',
		  `rep_opt` varchar(32) NOT NULL DEFAULT '',
		  `room_id` int(11) NOT NULL DEFAULT '1',
		  `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `create_by` varchar(80) NOT NULL DEFAULT '',
		  `name` varchar(80) NOT NULL DEFAULT '',
		  `type` char(1) NOT NULL DEFAULT 'E',
		  `description` text,
		  `rep_num_weeks` smallint(6) DEFAULT NULL,
		  `private` tinyint(1) NOT NULL DEFAULT '0',
		  `reminded` int(11) DEFAULT NULL,
		  PRIMARY KEY (`id`)
		) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
	";
	mysql_query($query);
}
function create_table_mrbs_room(){
	$query="
		CREATE TABLE IF NOT EXISTS `mrbs_room` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `area_id` int(11) NOT NULL DEFAULT '0',
		  `room_name` varchar(25) NOT NULL DEFAULT '',
		  `sort_key` varchar(25) NOT NULL DEFAULT '',
		  `description` varchar(60) DEFAULT NULL,
		  `capacity` int(11) NOT NULL DEFAULT '0',
		  `room_admin_email` text,
		  `custom_html` text,
		  PRIMARY KEY (`id`),
		  KEY `idxSortKey` (`sort_key`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
	";
	mysql_query($query);
}
function create_table_mrbs_variables(){
	$query="
		CREATE TABLE IF NOT EXISTS `mrbs_variables` (
		  `id` int(11) NOT NULL AUTO_INCREMENT,
		  `variable_name` varchar(80) DEFAULT NULL,
		  `variable_content` text,
		  PRIMARY KEY (`id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=3 ;
	";
	mysql_query($query);
}
function insert_mrbs_variables(){
	$query="
		INSERT INTO `mrbs_variables` (`id`, `variable_name`, `variable_content`) VALUES
		(1, 'db_version', '13'),
		(2, 'local_db_version', '1');
	";
	mysql_query($query);
}
function create_table_thesis(){
	$query="
			CREATE TABLE IF NOT EXISTS `thesis` (
		  `Id` int(11) NOT NULL AUTO_INCREMENT,
		  `TITLE` varchar(100) DEFAULT NULL,
		  `COMMITDATE` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
		  `PUBLISHER` varchar(100) DEFAULT NULL,
		  `PUBLISHDATE` date DEFAULT NULL,
		  `SEARCHCD` varchar(50) DEFAULT NULL,
		  `AUTHOR` int(15) DEFAULT NULL,
		  PRIMARY KEY (`Id`)
		) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=17 ;
	";
	mysql_query($query);
}
?>